<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<body>
	<p>
		Hello <b><%=request.getUserPrincipal().getName()%></b>!
	</p>
	<p>
	<ul>
		<li>Please select the application you want to review : </li>
		<table>
		<tr>
				<th>ID</th>
				<th>Name</th>
			</tr>
		<p>
			<%-- Import the java.sql package --%>
			<%@ page import="java.sql.*"%>
			<%-- -------- Open Connection Code -------- --%>
			<%
				session.setAttribute("userName", request.getUserPrincipal()
						.getName());
				Connection conn = null;
				PreparedStatement pstmt = null;
				ResultSet rs = null;

				try {
					// Registering Postgresql JDBC driver with the DriverManager
					Class.forName("org.postgresql.Driver");

					// Open a connection to the database using DriverManager
					conn = DriverManager
							.getConnection("jdbc:postgresql://localhost/admissions?"
									+ "user=postgres&password=27428572");
			%>
			<%
				// Begin transaction
					//insert Address
					conn.setAutoCommit(false);
					Statement stmt = conn.createStatement();
					rs = stmt
							.executeQuery("SELECT app_id,app_name FROM list_application WHERE reviewer_name='"
									+ request.getUserPrincipal().getName() + "'");
					if(rs != null)
					while (rs.next()) {
						int id = rs.getInt(1);
						%><tr><td><%=id%></td>
						<td><html:link action="/protected/reviewer/appReview">
						<html:param name="applicantName" value="<%=rs.getString(2)%>"/><%=rs.getString(2)%></html:link></td></tr>
					<% 
					}
					conn.setAutoCommit(true);

				}

				catch (SQLException e) {
					throw new RuntimeException(e);
				}

				finally {
					if (rs != null) {
						try {
							rs.close();
						} catch (SQLException e) {
						}
						rs = null;
					}
					if (pstmt != null) {
						try {
							pstmt.close();
						} catch (SQLException e) {
						}
						pstmt = null;
					}
					if (conn != null) {
						try {
							conn.close();
						} catch (SQLException e) {
						}
						conn = null;
					}

				}
			%>
		</table>
	</ul>

</body>
</html>